<?php

namespace app\index\controller;

use tian\Session;

class Chat extends Base
{
    public function index()
    {
        try {
            $this->fetch('index');
        } catch (\Throwable $e) {
            echo $e->getMessage();
        }
    }

    public function chatAct()
    {
        try {
            $role_id = Session::get('uid');

            $msg = input('msg');

            if ($msg == '') {
                returnJson(0, '内容不能为空');
            }

			$infoRole = model('Role')->getInfo($role_id);
            $add = [];
            
            $add['uid'] = $infoRole['uid'];
            $add['name'] = $infoRole['uname'];
			$add['msg'] = $msg;
            $add['addtime'] = time();
            model('Message')->add($add);

            returnJson(1, 'ok');
        } catch (\Throwable $e) {
            echo $e->getMessage();
        }
    }

}
